package com.segersten.othello.service.rest;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/todo")
public class TodoResource {
	// This method is called if XMLis request
	@GET
	@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public Todo getXML() {
		Todo todo = new Todo();
		todo.setSummary("This is my first todo");
		todo.setDescription("This is my first todo");
		return todo;
	}
	
	// This can be used to test the integration with the browser
	@GET
	@Produces( { MediaType.TEXT_XML })
	public Todo getHTML() {
		Todo todo = new Todo();
		todo.setSummary("This is my first todo");
		todo.setDescription("This is my first todo");
		return todo;
	}
	
	@GET
	@Path("/tomat")
	@Produces( { MediaType.APPLICATION_JSON })
	public Todo getTomat() {
		Todo todo = new Todo();
		todo.setSummary("This is my first todo " + MediaType.APPLICATION_XML + " " + MediaType.APPLICATION_JSON);
		todo.setDescription("tomat");
		return todo;
	}
	
	@GET
	@Path("/gurka/{boardId}")
	@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public Todo getXML(@PathParam(value = "boardId") String boardId) {
		Todo todo = new Todo();
		todo.setSummary("This is my first todo " + MediaType.APPLICATION_XML + " " + MediaType.APPLICATION_JSON);
		todo.setDescription("othello/"+boardId);
		return todo;
	}
	
	// This can be used to test the integration with the browser
	@GET
	@Path("/gurka/{boardId}")
	@Produces( { MediaType.TEXT_XML })
	public Todo getHTML(@PathParam(value = "boardId") String boardId) {
		Todo todo = new Todo();
		todo.setSummary("This is my first todo TEXT_XML");
		todo.setDescription("TEXT_XML othello/"+boardId);
		return todo;
	}

	@POST
	@Path("/gurka")
	@Produces({ "text/html" })
	public String postGurka(String request) {
		return "othello/" + request.replace("reg=", "");
	}


}